<?php
namespace app\index\model;

use think\Model;
use think\Session;

class Reserves extends Model
{
    /**
     * 计算价格
     * @param  [type] $caravan_id [description]
     * @param  [type] $start_date [description]
     * @param  [type] $end_date   [description]
     * @return [type]             [description]
     */
    public function calculatePrice($caravan_id, $start_date, $end_date)
    {
        $field  = '(CASE WHEN trusts THEN single_day_price ELSE single_day_coin END) AS amount, datetimes';
        $field .= ', (CASE WHEN trusts THEN "total_money" ELSE "travel_coin" END) AS types';

        $where = [
            'caravan_id' => $caravan_id,
            'shares'     => 1, 
            'datetimes' => [
                'between time', [
                    $start_date, 
                    $end_date
                ]
            ]
        ];

        $caravans = model('Calendar')->field($field)->where($where)->group('datetimes')->select()->toArray();
        return $caravans;
    }
}